//package com.yunhe.device.controller.device;
//
//import com.yunhe.common.model.PageParam;
//import com.yunhe.device.domain.device.Terminal;
//import com.yunhe.common.exception.ArgumentErrorException;
//import com.yunhe.common.exception.ObjectNotFoundException;
//import com.yunhe.common.exception.UniqueConstraintsException;
//import com.yunhe.common.model.DomainList;
//import com.yunhe.common.model.ResultObject;
//import com.yunhe.device.service.device.TerminalService;
//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiImplicitParam;
//import io.swagger.annotations.ApiImplicitParams;
//import io.swagger.annotations.ApiOperation;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.http.HttpStatus;
//import org.springframework.http.ResponseEntity;
//import org.springframework.web.bind.annotation.*;
//
//import java.util.Optional;
//
///**
// * 端子Controller
// * @author liuronglei
// * @desc 端子控制类定义
// */
//@Api(value = "terminal", description = "端子维护", tags = {"Model_Terminal"})
//@RestController
//@RequestMapping("/terminals")
//public class TerminalController {
//    @Autowired
//    private TerminalService terminalService;
//
//    /**
//     * 新增端子
//     * @param terminal 端子对象
//     */
//    @ApiOperation("新增端子")
//    @RequestMapping(method = RequestMethod.POST)
//    public ResponseEntity<ResultObject> post(
//            @RequestBody Terminal terminal)
//            throws ArgumentErrorException, UniqueConstraintsException, ObjectNotFoundException {
//        Terminal newTerminal = terminalService.createTerminal(terminal);
//        return new ResponseEntity<>(new ResultObject<>(newTerminal), HttpStatus.OK);
//    }
//
//    /**
//     * 批量新增端子
//     * @param domainList 端子对象列表
//     */
//    @ApiOperation("批量新增端子")
//    @RequestMapping(value = "/batch", method = RequestMethod.POST)
//    public ResponseEntity<ResultObject> post(
//            @RequestBody DomainList<Terminal> domainList)
//            throws ArgumentErrorException, UniqueConstraintsException, ObjectNotFoundException {
//        Iterable<Terminal> newTerminals = terminalService.createTerminal(domainList.getList());
//        return new ResponseEntity<>(new ResultObject<>(newTerminals), HttpStatus.OK);
//    }
//
//    /**
//     * 根据ID删除端子
//     * @param id id
//     */
//    @ApiOperation("根据ID删除端子")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "id", value = "端子ID", required = true, dataType = "Long", paramType = "path")
//    })
//    @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
//    public ResponseEntity<ResultObject> delete(
//            @PathVariable("id") Long id) {
//        terminalService.deleteTerminal(id);
//        return new ResponseEntity<>(new ResultObject<>(null), HttpStatus.OK);
//    }
//
//    /**
//     * 根据代码删除端子
//     * @param code 代码
//     */
//    @ApiOperation("根据代码删除端子")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "code", value = "代码", required = true, dataType = "long", paramType = "path")
//    })
//    @RequestMapping(value = "/byCode/{code}", method = RequestMethod.DELETE)
//    public ResponseEntity<ResultObject> deleteByCode(
//            @PathVariable("code") Long code) {
//        Long result = terminalService.deleteTerminalByCode(code);
//        return new ResponseEntity<>(new ResultObject<>(result), HttpStatus.OK);
//    }
//
//    /**
//     * 更新端子（更新全部字段）
//     * @param id ID
//     * @param terminal 端子对象
//     */
//    @ApiOperation("更新端子（更新全部字段）")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "Long", paramType = "path")
//    })
//    @RequestMapping(value = "/{id}", method = RequestMethod.PUT)
//    public ResponseEntity<ResultObject> put(
//            @PathVariable("id") Long id,
//            @RequestBody Terminal terminal)
//            throws ArgumentErrorException, UniqueConstraintsException, ObjectNotFoundException {
//        terminal.setId(id);
//        Terminal newTerminal = terminalService.updateTerminal(terminal);
//        return new ResponseEntity<>(new ResultObject<>(newTerminal), HttpStatus.OK);
//    }
//
//    /**
//     * 更新端子（更新指定字段）
//     * @param id ID
//     * @param code 代码
//     * @param devCode 设备代码
//     * @param connectivityNodeCode 连接节点代码
//     */
//    @ApiOperation("更新端子（更新指定字段）")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "long", paramType = "path"),
//            @ApiImplicitParam(name = "code", value = "代码", dataType = "long", paramType = "query"),
//            @ApiImplicitParam(name = "devCode", value = "设备代码", dataType = "long", paramType = "query"),
//            @ApiImplicitParam(name = "connectivityNodeCode", value = "连接节点代码", dataType = "long", paramType = "query")
//    })
//    @RequestMapping(value = "/{id}", method = RequestMethod.PATCH)
//    public ResponseEntity<ResultObject> patch(
//            @PathVariable("id") Long id,
//            @RequestParam("code") Optional<Long> code,
//            @RequestParam("devCode") Optional<Long> devCode,
//            @RequestParam("connectivityNodeCode") Optional<Long> connectivityNodeCode)
//            throws ArgumentErrorException, ObjectNotFoundException, UniqueConstraintsException {
//        Terminal newTerminal = terminalService.updateTerminal(id, code.orElse(null), devCode.orElse(null), connectivityNodeCode.orElse(null));
//        return new ResponseEntity<>(new ResultObject<>(newTerminal), HttpStatus.OK);
//    }
//
//    /**
//     * 根据设备ID获得端子对象
//     * @param id ID
//     */
//    @ApiOperation("根据ID获得端子对象")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "id", value = "设备ID", required = true, dataType = "Long", paramType = "path")
//    })
//    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
//    public ResponseEntity<ResultObject> get(
//            @PathVariable("id") Long id) {
//        Terminal terminal = terminalService.findByTerminalId(id);
//        return new ResponseEntity<>(new ResultObject<>(terminal), HttpStatus.OK);
//    }
//
//    /**
//     * 根据代码获得端子对象
//     * @param code 代码
//     */
//    @ApiOperation("根据代码获得端子对象")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "code", value = "代码", required = true, dataType = "Long", paramType = "path")
//    })
//    @RequestMapping(value = "/byCode/{code}", method = RequestMethod.GET)
//    public ResponseEntity<ResultObject> getByCode(
//            @PathVariable("code") Long code) {
//        Terminal terminal = terminalService.findByCode(code);
//        return new ResponseEntity<>(new ResultObject<>(terminal), HttpStatus.OK);
//    }
//
//    /**
//     * 根据条件获得端子列表
//     */
//    @ApiOperation("根据条件获得端子列表")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "systemId", value = "系统ID", required = true, dataType = "String", paramType = "path")
//    })
//    @RequestMapping(method = RequestMethod.GET)
//    public ResponseEntity<ResultObject> search(
//            @ModelAttribute PageParam pageParam) {
//        Iterable<Terminal> results = terminalService.findTerminals(pageParam);
//        return new ResponseEntity<>(new ResultObject<>(results), HttpStatus.OK);
//    }
//}